package com.chuangke.file.controller;

import java.math.BigInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;
import com.chuangke.common.utils.SecurityUtils;
import com.chuangke.file.service.FileDbankService;

/**
 * 【请填写功能名称】Controller
 * 
 * @author chuangke
 * @date "2020-09-02"
 */
@RestController
@RequestMapping("/file/dbank")
public class FileDbankController {
    
    @Autowired
    private FileDbankService fileDbankService;
    
    @PreAuthorize("hasAuthority('login:action')")
    @GetMapping("/listOwns/{dbankType}")
    public HttpResult list(@PathVariable String dbankType) {
    	String userId = SecurityUtils.getUserId() ;
    	if("all".equals(dbankType)) {
    		dbankType = "" ;
    	}
        return HttpResult.ok(fileDbankService.listAuthDbanks(userId,dbankType));
    }
    
    //共享文件的网盘
    @PreAuthorize("hasAuthority('login:action')")
    @GetMapping("/listShare/{dbankType}")
    public HttpResult listShare(@PathVariable String dbankType) {
    	String userId = SecurityUtils.getUserId() ;
    	if("all".equals(dbankType)) {
    		dbankType = "" ;
    	}
        return HttpResult.ok(fileDbankService.listAuthFileDbanks(userId,dbankType));
    }
    
    @PreAuthorize("hasAuthority('login:action')")
    @PostMapping("/expand")
    public HttpResult expand(String id,BigInteger space) {
    	fileDbankService.expandSpace(id, space) ;
        return HttpResult.ok();
    }

    @PreAuthorize("hasAuthority('login:action')")
    @GetMapping("/find/{id}")
    public HttpResult find(@PathVariable String id) {
        return HttpResult.ok(fileDbankService.loadDbankWithSpaceById(id));
    }
    
    @PreAuthorize("hasAuthority('login:action')")
    @GetMapping("/list")
    public HttpResult find() {
        return HttpResult.ok(fileDbankService.listDbank());
    }

}
